package hz.mobileproject.pda.toolsmanager.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.xutils.view.annotation.ViewInject;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.toolsmanager.bean.response.RP_SelectSmallToolsHistory;
import hz.mobileproject.pda.ui.base.BaseCustomAdapter;

/**
 * Created by Lc on 2018/5/28.
 */

public class SmallToolListAdapter extends BaseCustomAdapter<RP_SelectSmallToolsHistory,SmallToolListAdapter.VH> {

    private OnBtnClickListener onBtnClickListener;

    public SmallToolListAdapter(Context mContext, List<RP_SelectSmallToolsHistory> list) {
        super(mContext, list);
    }

    @Override
    protected int bindView() {
        return R.layout.item_small_tools_history;
    }

    @Override
    protected VH createViewHolder() {
        return new VH();
    }

    @Override
    protected void bindData(final int position, View convertView, VH vh) {
        vh.tv_small_tool_name.setText(mList.get(position).getTool_name());
        vh.tv_user_person_name.setText(mList.get(position).getUse_person_name());
        vh.btn_small_tool_retrieve.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onBtnClickListener !=null){
                    onBtnClickListener.onRetrieveClick(mList.get(position));
                }
            }
        });
        vh.btn_small_tool_scrap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onBtnClickListener !=null){
                    onBtnClickListener.onScrapClick(mList.get(position));
                }
            }
        });
    }

    public OnBtnClickListener getOnBtnClickListener() {
        return onBtnClickListener;
    }

    public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
        this.onBtnClickListener = onBtnClickListener;
    }

    class VH{
        @ViewInject(R.id.tv_small_tool_name)
        private TextView tv_small_tool_name;
        @ViewInject(R.id.tv_user_person_name)
        private TextView tv_user_person_name;
        @ViewInject(R.id.btn_small_tool_retrieve)
        private Button btn_small_tool_retrieve;
        @ViewInject(R.id.btn_small_tool_scrap)
        private Button btn_small_tool_scrap;

    }

    public interface OnBtnClickListener{
        void onRetrieveClick(RP_SelectSmallToolsHistory smallToolsHistory);
        void onScrapClick(RP_SelectSmallToolsHistory smallToolsHistory);
    }
}
